package com.a16.yuejian.yuejian.fragment;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.a16.yuejian.yuejian.R;
import com.a16.yuejian.yuejian.activity.SerachActivity;
import com.a16.yuejian.yuejian.adapter.ClubAdapter;
import com.a16.yuejian.yuejian.javabean.Club;
import com.a16.yuejian.yuejian.listener.ClubListListener;
import com.a16.yuejian.yuejian.model.ClubModel;

import java.util.List;

public class ClubFragment extends Fragment {
    private ImageView club_serach;
    private View view=null;
    private RecyclerView recyclerview;

    ClubListListener clubListListener = new ClubListListener() {
        @Override
        public void onResponse(List<Club> clubList) {
            recyclerview.setAdapter(new ClubAdapter(getActivity(),clubList));
        }

        @Override
        public void onFail() {

        }
    };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState)
    {
        view=inflater.inflate(R.layout.fragment_club, container, false);
        initRecyclerView(view);
        getData();
        initEvent();
        return view;
    }

    private void initEvent() {
        club_serach.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), SerachActivity.class);
                getActivity().startActivity(intent);
            }
        });
    }

    private void getData() {
        ClubModel clubModel = new ClubModel();
        clubModel.allclub(clubListListener);
    }

    private void initRecyclerView(View view) {
        recyclerview = (RecyclerView)view.findViewById(R.id.rv_club);
        recyclerview.setLayoutManager(new LinearLayoutManager(this.getActivity()));
        club_serach = (ImageView)view.findViewById(R.id.club_serach);

    }
}

